package com.longrise.android.byjk.plugins.tabthird.invoice;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/11/21.
 * 消费记录详情和购买的课程的adapter
 */

public class ConsumeDetailRcvAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {

    private List<EntityBean> mListBeans = new ArrayList<>();
    private List<EntityBean> mList;
    //mAdapterType=true 代表消费记录详情,false代表购买的课程
    public boolean mAdapterType;

    public ConsumeDetailRcvAdapter(boolean mAdapterType) {
        super(R.layout.item_consume_detail);
        this.mAdapterType = mAdapterType;
    }


    public void refreshData(EntityBean[] beans) {
        mListBeans.clear();
        for (EntityBean bean : beans) {
            mListBeans.add(bean);
        }
        setNewData(mListBeans);
    }

    public void setDatas(EntityBean[] beans, boolean isLoadmore) {
        if(isLoadmore){
          List<EntityBean>  list = new ArrayList<>();
            if (beans != null) {
                for (int x = 0; x < beans.length; x++) {
                    EntityBean bean = beans[x];
                    list.add(bean);
                }
            }
            mListBeans.addAll(list);
        }else{
            mListBeans.clear();
            if (beans != null) {
                for (int x = 0; x < beans.length; x++) {
                    EntityBean bean = beans[x];
                    mListBeans.add(bean);
                }
            }
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, final EntityBean item) {
        final int position = helper.getLayoutPosition();
        final View convertView = helper.getConvertView();
        ImageView iv = (ImageView) convertView.findViewById(R.id.item_consume_detail_iv);
        final TextView tvTitle = (TextView) convertView.findViewById(R.id.item_train_my_tv1);
        TextView tvDate = (TextView) convertView.findViewById(R.id.item_train_my_tv2);

        String realpic = item.getString("cdnurl", "");

        Glide.with(mContext)
                .load(realpic)
                .placeholder(mContext.getResources().getDrawable(R.drawable.img03))
                .crossFade()
                .into(iv);
        Glide.get(mContext).clearMemory();

//        PrintLog.e("ConsumeDetailRcvAdapter","mListBeans=:"+mListBeans.size());
        tvTitle.setText(item.getString("subjectname"));
        tvDate.setText("¥" + item.getString("payprice"));

        //item 分割线
        if(mAdapterType){
            if(mListBeans.size() == position){
                helper.setVisible(R.id.item_train_my_divider2,false);
            }else{
                helper.setVisible(R.id.item_train_my_divider2,true);
            }
        }else {
            if(mListBeans.size()-1 == position){
                helper.setVisible(R.id.item_train_my_divider2,false);
            }else{
                helper.setVisible(R.id.item_train_my_divider2,true);
            }
        }
    }

}
